package brickdestroyer.math;

/**
 * This class represents a rectangle shape.
 * 
 * @author Momchil Atanasov
 */
public class Rectangle2D extends Shape2D {
    
    public static final float DEFAULT_WIDTH = 80.0f;
    
    public static final float DEFAULT_HEIGHT = 40.0f;
   
    protected float halfWidth = DEFAULT_WIDTH / 2.0f;

    protected float halfHeight = DEFAULT_HEIGHT / 2.0f;

    public Rectangle2D() {
        this(0.0f, 0.0f, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    }

    public Rectangle2D(Vector2D position, float width, float height) {
        this(position.x, position.y, width, height);
    }
    
    public Rectangle2D(float x, float y, float width, float height) {
        super(x, y);
        this.halfWidth = width / 2.0f;
        this.halfHeight = height / 2.0f;
    }
    
    public Rectangle2D(Rectangle2D other) {
        this(other.x, other.y, other.getWidth(), other.getHeight());
    }
   
    public void setWidth(float value) {
        halfWidth = value / 2.0f;
    }
    
    public float getWidth() {
        return halfWidth * 2.0f;
    }

    public float getHalfWidth() {
        return halfWidth;
    }
    
    public void setHeight(float value) {
        halfHeight = value / 2.0f;
    }
    
    public float getHeight() {
        return halfHeight * 2.0f;
    }

    public float getHalfHeight() {
        return halfHeight;
    }
    
    public float getMinX() {
        return (x - halfWidth);
    }
    
    public float getMaxX() {
        return (x + halfWidth);
    }
    
    public float getMinY() {
        return (y - halfHeight);
    }
    
    public float getMaxY() {
        return (y + halfHeight);
    }
    
    public float getSmallestSize() {
        return Math.min(getHalfWidth(), getHalfHeight());
    }
}
